<?php


namespace App\Domain\Account\Dao;


use App\Domain\Account\Models\AccountModel;
use App\Http\Models\Permission\PermissionModel;
use Illuminate\Database\Eloquent\Builder;

class AccountDao
{

    public function del($id)
    {
        $ids = explode(',',$id);
        return AccountModel::whereIn('id', $ids)->update(['status' => '0']);
    }

    public function findByAccount($account)
    {
        return AccountModel::where('account', $account)->where('status', 1)->first();
    }

    public function findByAccountExcludeUid($account, $uid)
    {
        return AccountModel::where('account', $account)->where('status', 1)
            ->where('uid', '<>', $uid)
            ->first();
    }

    public function findById($id)
    {
        return AccountModel::where('id', $id)->where('status', 1)->first();
    }

    public function findByUid($uid)
    {
        return AccountModel::where('uid', $uid)->where('status', 1)->first();
    }

    /**
     * 创建账号
     * @param $params
     * @return AccountModel
     */
    public function create($params)
    {
        $params = array_filter_null($params);
        return AccountModel::create($params)->id;
    }

    /**
     * 修改账号
     * @param AccountModel $model
     * @param $param
     * @return AccountModel
     */
    public function update(AccountModel $model, $param)
    {
        $param = array_filter_null($param);
        $model->fill($param)->save();
        return $model;
    }



}
